gtk-demo: Add a shortcuts window
authorMatthias Clasen <mclasen@redhat.com>
Mon, 27 Apr 2020 02:14:10 +0000 (22:14 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 27 Apr 2020 02:14:10 +0000 (22:14 -0400)
Its not very impressive here, but still good to have.

demos/gtk-demo/demo.gresource.xml
demos/gtk-demo/help-overlay.ui [new file with mode: 0644]
demos/gtk-demo/main.c
demos/gtk-demo/main.ui

index 850750e5ef9338e1972fa8787cf71617b22bb675..19a2f8a168a042f390052c54957403f323cc37ac 100644 (file)
     <file>icons/16x16/status/battery-caution-charging-symbolic.symbolic.png</file>
     <file>icons/16x16/categories/applications-other.png</file>
   </gresource>
+  <gresource prefix="/org/gtk/Demo4/gtk">
+    <file preprocess="xml-stripblanks">help-overlay.ui</file>
+  </gresource>
 </gresources>
diff --git a/demos/gtk-demo/help-overlay.ui b/demos/gtk-demo/help-overlay.ui
new file mode 100644 (file)
index 0000000..ae172ee
--- /dev/null
@@ -0,0 +1,25 @@
+<interface>
+  <object class="GtkShortcutsWindow" id="help_overlay">
+    <child>
+      <object class="GtkShortcutsSection">
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="title">General</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="accelerator">F1</property>
+                <property name="title">Show About Dialog</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="accelerator">&lt;Control&gt;q</property>
+                <property name="title">Quit</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
index 53f2f04d9beafc31b8171e12ed92b8c3af2aca27..a31036d9166c21a1598d0c57c932d1d2e6e20605 100644 (file)
@@ -1186,6 +1186,14 @@ main (int argc, char **argv)
     { "quit", activate_quit, NULL, NULL, NULL },
     { "inspector", activate_inspector, NULL, NULL, NULL },
   };
+  struct {
+    const gchar *action_and_target;
+    const gchar *accelerators[2];
+  } accels[] = {
+    { "app.about", { "F1", NULL } },
+    { "app.quit", { "<Control>q", NULL } },
+  };
+  int i;
 
   /* Most code in gtk-demo is intended to be exemplary, but not
    * these few lines, which are just a hack so gtk-demo will work
@@ -1203,6 +1211,9 @@ main (int argc, char **argv)
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
 
+  for (i = 0; i < G_N_ELEMENTS (accels); i++)
+    gtk_application_set_accels_for_action (app, accels[i].action_and_target, accels[i].accelerators);
+
   g_application_add_main_option (G_APPLICATION (app), "version", 0, 0, G_OPTION_ARG_NONE, "Show program version", NULL);
   g_application_add_main_option (G_APPLICATION (app), "run", 0, 0, G_OPTION_ARG_STRING, "Run an example", "EXAMPLE");
   g_application_add_main_option (G_APPLICATION (app), "list", 0, 0, G_OPTION_ARG_NONE, "List examples", NULL);
index d4cc88a96fbb960c68b486e3ae262676768eb02e..5256095fc675f4ab8311886b29589e190afca2c8 100644 (file)
@@ -6,6 +6,10 @@
         <attribute name="label" translatable="yes">_Inspector</attribute>
         <attribute name="action">app.inspector</attribute>
       </item>
+      <item>
+        <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
+        <attribute name="action">win.show-help-overlay</attribute>
+      </item>
       <item>
         <attribute name="label" translatable="yes">_About GTK Demo</attribute>
         <attribute name="action">app.about</attribute>